package cn.tpshion.devops.domain.entity;

import cn.tpshion.devops.common.enums.MsgType;
import lombok.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Getter
@Setter
@ToString
public class MsgData<T> implements Serializable {

    private static final long serialVersionUID = 2715825256630462175L;

    private String type;

    private String msg;

    private T data;

    private String time;

    public MsgData(MsgType msgType){
        this.type = msgType.getType();
        this.time = getTime();
    }

    public MsgData(MsgType msgType, String msg){
        this.type = msgType.getType();
        this.msg = msg;
        this.time = getTime();
    }

    public String getTime(){
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}
